<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/" + package + "/dao/" + fileName + "DaoImpl.java"/>
/*
 * File name : ${fileName}DaoImpl.java ${doc.date}
 * Copyright ${doc.copyright}. All rights reserved.
 */
package ${package?replace("/", ".")}.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.xust.common.Result;
import ${package?replace("/", ".")}.domain.${fileName};

/**
 * Interface ${fileName}DaoImpl
 * ${fileName} dao Implementation.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
@Repository("${table.name?uncap_first}Dao")
public class ${fileName}DaoImpl {

	private final static Log logger = LogFactory.getLog(${table.name?cap_first}DaoImpl.class);
	
	@Autowired
	private ${table.name?cap_first}Mapper ${table.name?uncap_first}Mapper;
	
	/**
	 * Insert new ${fileName} object.
	 * @param newValue New object.
	 * @return The id of new object.
	 */
	@Transactional
	public int insert(${fileName} newValue){
		${table.name?uncap_first}Mapper.insert(newValue);
		return newValue.getId().intValue();
	}
	
	/**
	 * Delete all objects.
	 * @return The number of rows affected.
	 */
	public int deleteAll(){
		return ${table.name?uncap_first}Mapper.deleteAll();
	}

	/**
	 * Delete object by id.
	 * @param id Target id.
	 * @return The number of rows affected.
	 */
	public int deleteById(int id){
		return ${table.name?uncap_first}Mapper.deleteById(id);
	}
	
	/**
	 * Delete objects which id were included in items array.
	 * @param items Target ids.
	 * @return The number of rows affected.
	 */
	public int deleteItems(Integer[] items){
		return ${table.name?uncap_first}Mapper.deleteItems(items);
	}

	/**
	 * Retrieve object by id.
	 * @param id Target ids.
	 * @return Target object.
	 */
	@Transactional(readOnly=true) 
	public ${table.name?cap_first} findById(int id){
		return ${table.name?uncap_first}Mapper.findById(id);
	}
	
	/**
	 * Retrieve all objects.
	 * @return Target objects.
	 */
	@Transactional(readOnly=true) 
	public List<${table.name?cap_first}> findAll(){
		return ${table.name?uncap_first}Mapper.findAll();
	}

	/**
	 * Retrieve objects in specified page.
	 * @param offset
	 * @param limit
	 * @return Target objects.
	 */
	@Transactional(readOnly=true) 
	public List<${fileName}> findPage(int offset, int limit){
		logger.debug("offset:" + offset + " limit:" + limit);
		return ${table.name?uncap_first}Mapper.findPage(new RowBounds(offset, limit));
	}
	
	
	/**
	 * Update specified object.
	 * @param newValue Target object.
	 * @return The number of rows affected.
	 */
	@Transactional 
	public int update(${fileName} newValue){
		return ${table.name?uncap_first}Mapper.update(newValue);
	}

	/**
	 * Retrieve the number of objects.
	 * @return The number of objects.
	 */
	public int size(){
		return ${table.name?uncap_first}Mapper.size();
	}

	public ${table.name?cap_first}Mapper get${table.name?cap_first}Mapper() {
		return ${table.name?uncap_first}Mapper;
	}

	public void set${table.name?cap_first}Mapper(${table.name?cap_first}Mapper ${table.name?uncap_first}Mapper) {
		this.${table.name?uncap_first}Mapper = ${table.name?uncap_first}Mapper;
	}
}
</#list>